/*
 * Copyright (C) 2014 Lucid Wolf
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.lucidhex.hex;

import com.lucidhex.hex.LucidIndex;
import com.lucidhex.hex.LucidCoord;

/**
 *
 * @author Wolf
 */
public class PlaneCoord {
    private final double[][] toMapFromErf = {{Math.sqrt(3.0), Math.sqrt(3.0)/2.0},{0.0, 1.5}};
    private double x = 0.0;  // similar to q but long
    private double y = 0.0;  // similar to r 
    public PlaneCoord(double x, double y){
        this.x = x;
        this.y = y;
    }
    public PlaneCoord(LucidIndex eC){
        this.x = eC.Q()* toMapFromErf[0][0] + eC.R()* toMapFromErf[0][1];
        this.y = eC.Q()* toMapFromErf[1][0] + eC.R()* toMapFromErf[1][1];
    }    
    public PlaneCoord(LucidCoord eC){
        this.x = eC.Q()* toMapFromErf[0][0] + eC.R()* toMapFromErf[0][1];
        this.y = eC.Q()* toMapFromErf[1][0] + eC.R()* toMapFromErf[1][1];
    }    
    public PlaneCoord(PlaneCoord e, PlaneCoord s){
        this.x = (e.X() + s.X())/2.0;
        this.y = (e.Y() + s.Y())/2.0;
    }    
    public double X(){
        return x;
    }
    public double Y(){
        return y;
    }
    public LucidCoord getErfCoord(){
        return new LucidCoord(this);
    }
    public LucidIndex getErfIndex(){
        return new LucidIndex(new LucidCoord(this));
    }

}
